1. /* sdfacos.cpp by K.Tsuru */
  2. // function ID 3101 DRADIX
  3. /****************************************************************
  4. SDouble class
  5. arccos x
  6. If |x| is very close to one, the formura
  7. arccos x = arcsin(sqrt((1-x)*(1+x))
  8. is used.
  9. When x = 1.0 - 10^(-100), test whether a full precision can be
  10. obtained or not.
  11. ****************************************************************/
  12. #ifndef SN_H
  13. #include "sn.h"
  14. #endif
  15. SDouble Acos(const SDouble& x){
  16. if(x.Sign(3101) == 0) return MPi2();// x = 0, pi/2
  17. if(x.IsOne()){ // |x| = 1
  18. if(x.Sign() < 0) return Pi(); // x = -1
  19. return 0.0; // x = 1
  20. }
  21. SDouble r;
  22. bool nearlyOne = false; // 1-|x| << 1.0 ?
  23. if(x.Sign() > 0) r = ONE - x; // must be r = 1.0 - |x| >= 0
  24. else r = ONE + x;
  25. if(r.NetRdxExp() < -1) nearlyOne = true;// |r| < 10^(-2*DFIGURES) = 1e-8
  26. if(r.Sign() < 0) x.SetError(x.DOMAIN_ERR, "Acos",3101); // |x|>1
  27. if(nearlyOne){ // by a formula arccos x = arcsin sqrt(1-x*x)
  28. if(x.Sign() > 0) r *= (ONE + x);
  29. else r *= (ONE - x);
  30. SDouble x1 = Sqrt(r); // r = 1-x^2, x1 < 1e-4
  31. r = Asin(x1); // r > 0 and 0 < x1 << 1.0
  32. if(x.Sign() < 0) r = Pi() - r; // arccos x = pi - arccos(-x)
  33. } else r = MPi2() - Asin(x); // pi/2 - arcsin x
  34. return r;
  35. }

sdfacos.cpp : last modifiled at 2016/08/29 16:42:52(1,283 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).